package org.come.mouslisten;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;
import java.util.List;

import javax.swing.ImageIcon;

import org.come.Frame.ZhuFrame;
import org.come.Jpanel.TransferJpanel;
import org.come.entity.Goodstable;
import org.come.until.AccessSuitMsgUntil;
import org.come.until.MessagrFlagUntil;

public class TransferEquiMouslisten implements MouseListener {

    private int index;
    private TransferJpanel transferJpanel;
    private int type;

    public TransferEquiMouslisten(int index, TransferJpanel transferJpanel, int type) {
        this.index = index;
        this.transferJpanel = transferJpanel;
        this.type = type;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        // 获取所需要的装备信息
        List<Goodstable> goodstables = AccessSuitMsgUntil.accessIdlEqu(type);
        if (goodstables == null) {
            return;
        }
        Goodstable goodstable = null;
        // 右键点击
        if (e.getButton() == MouseEvent.BUTTON3) {
            if (type == 1) {// 装备
                if ((index + 1 + TransferJpanel.page2 * 9) > goodstables.size()) {
                    return;
                }
                if (goodstables.get(index + TransferJpanel.page2 * 9) != null) {
                    goodstable = goodstables.get(index + TransferJpanel.page2 * 9);
                }
                if (goodstable == null) {
                    return;
                }
                // 将装备的图片放上去
                TransferJpanel.getLabzb().setIcon(
                        new ImageIcon(new ImageIcon("img/item/" + goodstable.getSkin() + ".png").getImage()
                                .getScaledInstance(50, 50, 10)));
                TransferJpanel.setGoodstable(goodstable);
                // 判断套装是否已经放上去
                if (TransferJpanel.getGoodstableBean().getGoodstable() != null) {
                    // 所需消耗的金钱和灵修值
                    TransferJpanel.setMoney(new BigDecimal(100000));
                    // 判断是什么品质的套装 -- 所需灵修值：10-20-40-80-160
                    // 获取转移所需灵修值
                    TransferJpanel.setValue(new BigDecimal(AccessSuitMsgUntil.getSxlxz(TransferJpanel
                            .getGoodstableBean().getGoodstable().getValue())));
                    TransferJpanel.getWorkshopBtn().setText("转移");
                }
            } else if (type == 2) {// 套装
                if ((index + 1 + TransferJpanel.page * 9) > goodstables.size()) {
                    return;
                }
                if (goodstables.get(index + TransferJpanel.page * 9) != null) {
                    goodstable = goodstables.get(index + TransferJpanel.page * 9);
                }
                // 将套装的图片放上去
                TransferJpanel.getLabtz().setIcon(
                        new ImageIcon(new ImageIcon("img/item/" + goodstable.getSkin() + ".png").getImage()
                                .getScaledInstance(50, 50, 10)));
                // 将套装放上去
                TransferJpanel.getGoodstableBean().setGoodstable(goodstable);
                // 判断装备是否已经放上去
                if (TransferJpanel.getGoodstable() != null) {
                    // 所需消耗的金钱和灵修值
                    TransferJpanel.setMoney(new BigDecimal(100000));
                    // 拆解不需要灵修值
                    TransferJpanel.setValue(new BigDecimal(AccessSuitMsgUntil.getSxlxz(goodstable.getValue())));
                    TransferJpanel.getWorkshopBtn().setText("转移");
                } else {
                    // 所需消耗的金钱和灵修值
                    TransferJpanel.setMoney(new BigDecimal(100000));
                    // 拆解不需要灵修值
                    TransferJpanel.setValue(null);
                    TransferJpanel.getWorkshopBtn().setText("拆解");
                }
            }
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
        List<Goodstable> listroleequi = AccessSuitMsgUntil.accessIdlEqu(type);// 获取空闲的装备
        Goodstable goodstable = null;
        if (type == 1) {
            if ((index + 1 + TransferJpanel.page2 * 9) > listroleequi.size()) {
                return;
            }
            if (listroleequi.get(index + TransferJpanel.page2 * 9) != null) {
                goodstable = listroleequi.get(index + TransferJpanel.page2 * 9);
            }
        } else if (type == 2) {
            if ((index + 1 + TransferJpanel.page * 9) > listroleequi.size()) {
                return;
            }
            if (listroleequi.get(index + TransferJpanel.page * 9) != null) {
                goodstable = listroleequi.get(index + TransferJpanel.page * 9);
            }
        }
        if (goodstable != null) {
            ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
        }
    }

    @Override
    public void mouseExited(MouseEvent e) {
        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
        ZhuFrame.getZhuJpanel().cleargoodtext();
    }

}
